home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12339 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.0 KB

  1. Path: solon.com!not-for-mail
  2. From: seebs@solutions.solon.com (Peter Seebach)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Settle a bet please
  5. Date: 30 Mar 1996 10:40:56 -0600
  6. Organization: Usenet Fact Police (Undercover)
  7. Message-ID: <4jjo6o$cqj@solutions.solon.com>
  8. References: <4jfopb$o9n@news1.sympatico.ca> <KASPER.96Mar29073654@acm.org> <mjs.828111568@hubcap> <KASPER.96Mar30085147@acm.org>
  9. NNTP-Posting-Host: solutions.solon.com
  10.  
  11. In article <KASPER.96Mar30085147@acm.org>,  <kasperowski@acm.org> wrote:
  12. >In private e-mail, someone said the same thing to me, and I replied,
  13. >"sure, I guess you're right."  I was wrong -- this is illegal.
  14.  
  15. Nope.  It's a special case exception, which is mentioned explicitly in
  16. the standard.  K&R should mention it.
  17.  
  18. >In ANSI C, 
  19.  
  20. > char name[7] = "My name";
  21.  
  22. >which is the same as
  23.  
  24. > char name[7] = {'M', 'y', ' ', 'n', 'a', 'm', 'e', '\0'};
  25.  
  26. But it isn't.  It's a special case.  6.5.7:
  27.     An array of character type may be initialized by a character
  28.     string literal, optionally enclosed in barces.  Successive
  29.     characters of the character string literal (including the
  30.     terminating null character IF THERE IS ROOM OR IF THE ARRAY
  31.     IS OF UNKNOWN SIZE) initialize the elements of the array.
  32.  
  33.  
  34. >is *not* legal.  Section A8.7 on p. 219 of Appendix A of my copy of
  35. >K&R's _The C Programming Language_, 2nd ed., says:
  36.  
  37. > If the array has fixed size, the number of initializers may not
  38. > exceed the number of members of the array . . .
  39.  
  40. And then goes on to say, in the next paragraph, that initializing with
  41. a string literal is a special case, and says
  42.   "if its size is fixed, the number of characters in the string, NOT
  43.    COUNTING THE TERMINATING NULL CHARACTER, must not exceed the size of
  44.    the array."
  45.  
  46. This is a feature, so things like
  47.     char octdig[8] = "01234567";
  48. work.
  49.  
  50. -s
  51. -- 
  52. Peter Seebach - seebs@solon.com - Copyright 1996 Peter Seebach.
  53. C/Unix wizard -- C/Unix questions? Send mail for help.  No, really!
  54. FUCK the communications decency act.  Goddamned government.  [literally.]
  55. The *other* C FAQ - http://www.solon.com/~seebs/c/c-iaq.html
  56.